package com.kernel.streamDemo;

import java.io.*;
import java.nio.charset.StandardCharsets;

/****************************************
 * @name ByteArrayDemo
 * @description 内存操作流学习
 * @author 黄彬恒
 * @since 2018/8/17
 ***************************************/
public class ByteArrayStreamDemo {
    public static void main(String[] args) throws IOException {
        String str = "hello world!";
        InputStream inputStream;
        OutputStream outputStream;
        inputStream = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
        outputStream = new ByteArrayOutputStream();
        int temp;
        while ((temp = inputStream.read()) != -1) {
            char c = (char) temp;
            outputStream.write(Character.toUpperCase(c));
        }
        // 所有数据都在outputStream中
        String string = String.valueOf(outputStream);
        System.out.println(string);
        inputStream.close();
        outputStream.close();
    }
}
